/*
 * @Description:
 * @Version: 1.668
 * @Autor: 地虎降天龙
 * @Date: 2025-03-31 11:11:15
 * @LastEditors: 地虎降天龙
 * @LastEditTime: 2025-04-07 08:29:32
 */
import Layout from '@/layout'

function goto(to, from, next, microPath) {
  // 处理路径，确保带上 hash 模式的子应用路径
  const targetPath = to.fullPath.includes('#')
    ? to.fullPath
    : `${to.fullPath}#/${microPath}`
  window.history.replaceState(null, '', targetPath)
  next()
}

const microAppRouter = {
  path: '/vue-son',
  component: Layout,
  redirect: '/vue-son/index',
  name: 'vue-son',
  meta: {
    title: '普通hash路由子系统',
    icon: 'table'
  },
  children: [
    {
      path: 'index',
      component: () => import('@/views/Micro/index'),
      name: 'Micro1',
      meta: { title: 'index', icon: 'dashboard', noCache: false, isMicro: true, microPath: 'index' },
      beforeEnter: (to, from, next) => { goto(to, from, next, 'index') },
      props: { showButton: true }
    },
    {
      path: 'about',
      component: () => import('@/views/Micro/index'),
      name: 'Micro2',
      meta: { title: 'about', icon: 'dashboard', noCache: false, isMicro: true, microPath: 'about' },
      beforeEnter: (to, from, next) => { goto(to, from, next, 'about') }
    }
  ]
}
export default microAppRouter
